package com.ctgu.controller;

import com.ctgu.common.ResponseResult;
import com.ctgu.model.dto.LoginDto;
import com.ctgu.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginDto loginDto){
        return loginService.login(loginDto);
    }

    @GetMapping("/test")
    @PreAuthorize("@AYM.hasAuthority('*:*:*')")
    public ResponseResult test(String userName,String password){
        return new ResponseResult<>(200,userName+password);
    }

    @GetMapping("/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }

}
